<?php
/**
 * Created by PhpStorm.
 * User: wzy12
 * Date: 2018/11/12
 * Time: 2:02
 */

namespace app\common\model;


use think\Model;

class ReturnGoods extends Model
{
    /**
     * 退换货列表
     */
    public function resList($where){
        $query = $this -> where(1) -> alias('rg');

        // 筛选条件
        $is_where = $where;
        unset($is_where['page']);
        if($is_where) {
            if ($where) {
                // 查询发货状态
                if ($where['shipping_status'] || $where['shipping_status'] === '0') {
                    $query->where('shipping_status', $where['shipping_status']);
                }
                // 查询订单号
                if ($where['order_sn']) {
                    $query->where('order_sn', 'like', "%{$where['order_sn']}%");
                }
                // 查询订单号
                if ($where['consignee']) {
                    $query->where('consignee', 'like', "%{$where['consignee']}%");
                }
            }
        }

        $list = $query -> join('Order o', 'rg.order_id = o.id')
            -> field('o.order_sn,o.add_time,o.consignee,o.mobile,o.shipping_name,o.shipping_price,o.pay_time,o.order_amount,rg.status')
            -> paginate(10);

        return $list;
    }
}